require("../../assets/css/normalize.css");
require("../../assets/css/reset.css");
require("../../assets/fonts/iconfont.css");
require("../../assets/css/tabbar.less");
require("./mine_modify.less");
// 引入模块
const dom = require("../../utils/dom.js");
const axios = require("axios");
document.addEventListener("DOMContentLoaded", function () {
	dom.get("#back").addEventListener("click", function () {
		history.back();
	});
	//性别
	dom.get("#gender").addEventListener("click", function () {
		weui.picker(
			[
				{
					label: "男",
					value: 0,
				},
				{
					label: "女",
					value: 1,
				},
				{
					label: "未定义",
					value: 2,
				},
			],
			{
				onConfirm: function (result) {
					dom.get("#gender").textContent = result[0].label;
				},
				title: "单列选择器",
			}
		);
	});
	// 生日选择
	dom.get("#birthday").addEventListener("click", function () {
		weui.datePicker({
			start: 1950,
			end: new Date().getFullYear(),
			onConfirm: function (result) {
				let a = result[0].value + "-" + result[1].value + "-" + result[2].value;
				dom.get("#birthday").textContent = a;
			},
			title: "多列选择器",
		});
	});
	// 头像上传;
	// let token = localStorage.getItem("token");
	// axios.defaults.headers.common["Authorization"] = "Bearer " + token;
	// dom.get("#avatorbox").addEventListener("change", function () {
	// 	let fd = new FormData();
	// 	fd.append("file", this.files[0]);
	// 	axios
	// 		.post("http://fitness.h5.itsource.cn:3701/api/shared/uploadPortrait", fd)
	// 		.then((res) => {
	// 			console.log(res);
	// 			if (res.data.errno === 0) {
	// 				//上传成功
	// 				dom.get("#avator").src =
	// 					"http://fitness.h5.itsource.cn:3701" + res.data.data.url;
	// 			} else {
	// 				//上传失败
	// 				alert("上传失败");
	// 			}
	// 		});
	// });
	// 省市二级联动
	let provinceId = 0;
	dom.get("#province").addEventListener("click", function () {
		axios
			.get("http://fitness.h5.itsource.cn:3701/api/shared/province")
			.then((res) => {
				let resArr = res.data.data.map((v) => {
					return { label: v.name, value: v.id };
				});
				weui.picker(resArr, {
					onConfirm: function (result) {
						dom.get("#province").textContent = result[0].label;
						provinceId = result[0].value;
					},
					title: "单列选择器",
				});
			});
	});
	//城市
	dom.get("#city").addEventListener("click", function () {
		axios
			.get(
				"http://fitness.h5.itsource.cn:3701/api/shared/city?provinceId=" +
					provinceId
			)
			.then((res) => {
				let cityArr = res.data.data.map((v) => {
					return { label: v.name, value: v.id };
				});
				weui.picker(cityArr, {
					onConfirm: function (result) {
						dom.get("#city").textContent = result[0].label;
					},
					title: "单列选择器",
				});
			});
	});
	//个性签名
	dom.get("#sign").addEventListener("input", function () {
		dom.get("#text").textContent = this.value.length;
	});
});
